package com.hk.shop.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hk.shop.base.dao.BaseDaoImpl;
import com.hk.shop.dao.CategoryDao;
import com.hk.shop.model.Category;
import com.hk.shop.page.PageInfo;

@Repository("categoryDao")
public class CategoryDaoImpl extends BaseDaoImpl<Category, Integer> implements CategoryDao {

	public Long countCategory() {
		String hql = "select count(*) from Category";
		return count(hql, null);
		
	}

	public List<Category> findAll() {
		String hql = "from Category";
		return super.query(hql, null);
	}

	public Category findOne(Integer cid) {
		String hql = "from Category c where c.cid = ?";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setParameter(0, cid);
		return (Category)query.uniqueResult(); 
	}

	public List<Category> findAll(Integer page) {
		String hql = "from Category";
		int rows = 10;
		int page1 = page;
		return findPage(new PageInfo(page1,rows) , hql).getContentList(); 
	}

	@Override
	public List<Category> findAllResult() {
		String hql = "from Category";
		return super.query(hql, null);
	}

}
